package com.financing.platform.dao.impl;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Service;

import com.financing.platform.dao.IProjectRiskDao;
import com.financing.platform.dto.ProjectRiskDTO;
import com.financing.platform.util.SqlName;

@Service("projectRiskDaoImpl")
public class ProjectRiskDaoImpl extends BaseDaoImpl implements IProjectRiskDao {

	public Integer addProjectRisk(ProjectRiskDTO projectRiskDTO) {
		
		try {
			this.sqlMapClient.insert(SqlName.insertProjectRisk, projectRiskDTO);
			return 1;
		} catch (SQLException e) {
			log.error("Add project risk error !", e);
			return 0;
		}
		
	}

	@SuppressWarnings("unchecked")
	public List<ProjectRiskDTO> queryProjectList(ProjectRiskDTO projectRiskDTO) {
		
		try {
			return this.sqlMapClient.queryForList(SqlName.searchProjectRiskByPid, projectRiskDTO);
		} catch (SQLException e) {
			log.error("Query project list error !", e);
			return Collections.emptyList();
		}
	}

	public int deleteProjectRisk(int projectId) throws SQLException {
		return this.sqlMapClient.delete(SqlName.deleteProjectRisk, projectId);
	}

}
